/**
 * 
 */
package io.dora.spring.parser;

import io.dora.conf.RegistryConfig;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

/**
 * registry节点处理类
 * 
 * @author zhaohongbo
 *
 */
public class RegistryDefinitionParser implements BeanDefinitionParser {

	@Override
	public BeanDefinition parse(Element element, ParserContext context) {
		RootBeanDefinition def = new RootBeanDefinition();

	    // 设置Bean Class
	    def.setBeanClass(RegistryConfig.class);
	    def.setLazyInit(false);

	    // 注册属性
	    String url = element.getAttribute("url");
	    String id = element.getAttribute("id");
	    
	    def.getPropertyValues().addPropertyValue("url", url);
	    def.getPropertyValues().addPropertyValue("id", id);
	    context.getRegistry().registerBeanDefinition(id, def);
	    return def;
	}

}
